package com.heima.storage.controller;

import com.heima.storage.service.IStorageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author mcm
 * @since 2021-09-22
 */
@RestController
@RequestMapping("/storage")
public class StorageController {

    @Autowired
    private IStorageService storageService;

    /**
     * 扣减库存
     *
     * @param code  商品编号
     * @param count 要扣减的数量
     * @return
     */
    @PutMapping("/{code}/{count}")
    public ResponseEntity deduct(@PathVariable("code") String code, @PathVariable("count") Integer count) {
        storageService.deduct(code, count);
        return ResponseEntity.ok().build();
    }

}
